﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using sapphirelang.AST.Exprs;
using sapphirelang.AST.Patterns;

namespace sapphirelang.AST.Stmts
{
    /* a loop can have multiple clauses;
     *   each clause is either a "while" clause or a "for" clause.
     * when a loop stmt is executed, each clause is run (in order),
     *   and if any clause fails, then the body is not executed.
     * this construct was shamelessly stolen from Robert Nystrom's
     *   language Magpie. (thank you, Nystrom!)
     *   
     * example:
     *   // pairs up each item with a 1-based index
     *   for item in collection
     *   for index in 1.up
     *      show("item " + index + " = " + item);
     */

    class LoopStmt : Stmt
    {
        public LoopHeader[] headers;
        public Stmt body;

        public LoopStmt(LoopHeader[] headers, Stmt body)
        {
            this.headers = headers;
            this.body = body;
        }
    }

    // a single line of a loop header
    abstract class LoopHeader
    {
    }
    // while cond
    class WhileLoopHeader : LoopHeader
    {
        public Expr cond;

        public WhileLoopHeader(Expr cond)
        {
            this.cond = cond;
        }
    }
    // for pat in iter
    class ForLoopHeader : LoopHeader
    {
        public Expr iter;
        public Pattern pat;

        public ForLoopHeader(Expr iter, Pattern pat)
        {
            this.iter = iter;
            this.pat = pat;
        }
    }
}
